#Boa:Dialog:CadastrarNovoRecurso

import wx
from Class_GerenciadorRecursos import *
from Class_ItemRecurso import *
from Class_ItemComida import *
from Class_ItemBebida import *
from Class_Usuario import *
from Class_Contato import *
def create(parent, TipoRecurso):
    return CadastrarNovoRecurso(parent, TipoRecurso)

[wxID_CADASTRARNOVORECURSO, wxID_CADASTRARNOVORECURSOBUTTON1, 
 wxID_CADASTRARNOVORECURSOBUTTON2, wxID_CADASTRARNOVORECURSORADIOBUTTON1, 
 wxID_CADASTRARNOVORECURSORADIOBUTTON2, wxID_CADASTRARNOVORECURSORADIOBUTTON3, 
 wxID_CADASTRARNOVORECURSORADIOBUTTON4, wxID_CADASTRARNOVORECURSOSTATICTEXT1, 
 wxID_CADASTRARNOVORECURSOSTATICTEXT2, wxID_CADASTRARNOVORECURSOSTATICTEXT3, 
 wxID_CADASTRARNOVORECURSOSTATICTEXT4, wxID_CADASTRARNOVORECURSOSTATICTEXT5, 
 wxID_CADASTRARNOVORECURSOSTATICTEXT6, wxID_CADASTRARNOVORECURSOSTATICTEXT7, 
 wxID_CADASTRARNOVORECURSOTEXTCTRL1, wxID_CADASTRARNOVORECURSOTEXTCTRL2, 
 wxID_CADASTRARNOVORECURSOTEXTCTRL3, wxID_CADASTRARNOVORECURSOTEXTCTRL4, 
 wxID_CADASTRARNOVORECURSOTEXTCTRL5, wxID_CADASTRARNOVORECURSOTEXTCTRL6, 
 wxID_CADASTRARNOVORECURSOTEXTCTRL7, wxID_CADASTRARNOVORECURSOWINDOW1, 
 wxID_CADASTRARNOVORECURSOWINDOW2, wxID_CADASTRARNOVORECURSOWINDOW3, 
 wxID_CADASTRARNOVORECURSOWINDOW4, 
] = [wx.NewId() for _init_ctrls in range(25)]

class CadastrarNovoRecurso(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_CADASTRARNOVORECURSO,
              name=u'CadastrarNovoRecurso', parent=prnt, pos=wx.Point(737, 278),
              size=wx.Size(262, 298), style=wx.DEFAULT_DIALOG_STYLE,
              title=u'Dialog Cadastrar Novo Recurso')
        self.SetClientSize(wx.Size(254, 265))
        self.Center(wx.BOTH)

        self.window1 = wx.Window(id=wxID_CADASTRARNOVORECURSOWINDOW1,
              name='window1', parent=self, pos=wx.Point(11, 10),
              size=wx.Size(231, 245), style=0)
        self.window1.Center(wx.VERTICAL)

        self.textCtrl1 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL1,
              name='textCtrl1', parent=self.window1, pos=wx.Point(112, 32),
              size=wx.Size(100, 21), style=0, value=u'')

        self.staticText1 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT1,
              label=u'Nome do Recurso', name='staticText1', parent=self.window1,
              pos=wx.Point(16, 32), size=wx.Size(84, 13), style=0)

        self.textCtrl2 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL2,
              name='textCtrl2', parent=self.window1, pos=wx.Point(112, 72),
              size=wx.Size(100, 56), style=wx.VSCROLL, value=u'')

        self.staticText2 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT2,
              label=u'Descri\xe7\xe3o do Recurso', name='staticText2',
              parent=self.window1, pos=wx.Point(32, 88), size=wx.Size(56, 40),
              style=0)

        self.staticText3 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT3,
              label=u'Tipo de Recurso', name='staticText3', parent=self.window1,
              pos=wx.Point(24, 152), size=wx.Size(77, 13), style=0)

        self.button1 = wx.Button(id=wxID_CADASTRARNOVORECURSOBUTTON1,
              label=u'Salvar', name='button1', parent=self.window1,
              pos=wx.Point(32, 208), size=wx.Size(75, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_CADASTRARNOVORECURSOBUTTON1)

        self.button2 = wx.Button(id=wxID_CADASTRARNOVORECURSOBUTTON2,
              label=u'Cancelar', name='button2', parent=self.window1,
              pos=wx.Point(128, 208), size=wx.Size(75, 23), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
              id=wxID_CADASTRARNOVORECURSOBUTTON2)

        self.textCtrl3 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL3,
              name='textCtrl3', parent=self.window1, pos=wx.Point(112, 152),
              size=wx.Size(96, 21), style=0, value=u'')
        self.textCtrl3.SetEditable(False)
        self.textCtrl3.Enable(False)

        self.window2 = wx.Window(id=wxID_CADASTRARNOVORECURSOWINDOW2,
              name='window2', parent=self, pos=wx.Point(248, 0),
              size=wx.Size(200, 176), style=0)
        self.window2.Show(False)

        self.staticText4 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT4,
              label=u'Email*', name='staticText4', parent=self.window2,
              pos=wx.Point(24, 24), size=wx.Size(30, 13), style=0)

        self.textCtrl4 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL4,
              name='textCtrl4', parent=self.window2, pos=wx.Point(88, 24),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl5 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL5,
              name='textCtrl5', parent=self.window2, pos=wx.Point(88, 64),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl6 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL6,
              name='textCtrl6', parent=self.window2, pos=wx.Point(88, 104),
              size=wx.Size(100, 21), style=0, value=u'')

        self.textCtrl7 = wx.TextCtrl(id=wxID_CADASTRARNOVORECURSOTEXTCTRL7,
              name='textCtrl7', parent=self.window2, pos=wx.Point(88, 144),
              size=wx.Size(100, 21), style=0, value=u'')

        self.staticText5 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT5,
              label=u'Telefone1*', name='staticText5', parent=self.window2,
              pos=wx.Point(24, 64), size=wx.Size(54, 13), style=0)

        self.staticText6 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT6,
              label=u'Telefone2', name='staticText6', parent=self.window2,
              pos=wx.Point(24, 104), size=wx.Size(48, 13), style=0)

        self.staticText7 = wx.StaticText(id=wxID_CADASTRARNOVORECURSOSTATICTEXT7,
              label=u'Telefone3', name='staticText7', parent=self.window2,
              pos=wx.Point(24, 144), size=wx.Size(48, 13), style=0)

        self.window3 = wx.Window(id=wxID_CADASTRARNOVORECURSOWINDOW3,
              name='window3', parent=self, pos=wx.Point(256, 184),
              size=wx.Size(104, 56), style=0)
        self.window3.Show(False)

        self.window4 = wx.Window(id=wxID_CADASTRARNOVORECURSOWINDOW4,
              name='window4', parent=self, pos=wx.Point(256, 240),
              size=wx.Size(104, 48), style=0)
        self.window4.Show(False)

        self.radioButton1 = wx.RadioButton(id=wxID_CADASTRARNOVORECURSORADIOBUTTON1,
              label=u'Salgada', name='radioButton1', parent=self.window3,
              pos=wx.Point(16, 8), size=wx.Size(56, 13), style=0)
        self.radioButton1.SetValue(True)

        self.radioButton2 = wx.RadioButton(id=wxID_CADASTRARNOVORECURSORADIOBUTTON2,
              label=u'Doce', name='radioButton2', parent=self.window3,
              pos=wx.Point(16, 32), size=wx.Size(40, 13), style=0)
        self.radioButton2.SetValue(True)

        self.radioButton3 = wx.RadioButton(id=wxID_CADASTRARNOVORECURSORADIOBUTTON3,
              label=u'Alcoolica', name='radioButton3', parent=self.window4,
              pos=wx.Point(16, 8), size=wx.Size(81, 13), style=0)
        self.radioButton3.SetValue(True)

        self.radioButton4 = wx.RadioButton(id=wxID_CADASTRARNOVORECURSORADIOBUTTON4,
              label=u'Nao-Alcoolica', name='radioButton4', parent=self.window4,
              pos=wx.Point(16, 32), size=wx.Size(81, 13), style=0)
        self.radioButton4.SetValue(True)

    def __init__(self, parent, TipoRecurso):
        self._init_ctrls(parent)
        
        self.textCtrl3.SetValue(TipoRecurso)
        self.GR = GerenciadorRecursos()
        
        if TipoRecurso == 'servicos':
            #Exibe Painel de contato
            self.window2.Show(True)
            self.window2.Center(wx.VERTICAL)
            self.window1.Center(wx.VERTICAL)
            self.SetClientSize(wx.Size(462, 270))
            
        elif TipoRecurso == 'bebidas':
            #Exibe Painel de escolha (Alcoolica ou nao)
            self.window4.Show(True)
            self.window4.Center(wx.VERTICAL)
            self.window1.Center(wx.VERTICAL)
            self.SetClientSize(wx.Size(367, 265))
        
        elif TipoRecurso == 'comidas':
            #Exibe painel de escolha(Salgada ou Doce)
            self.window3.Show(True)
            self.window3.Center(wx.VERTICAL)
            self.window1.Center(wx.VERTICAL)
            self.SetClientSize(wx.Size(367, 265))
        
    #Botao: "Salvar"
    def OnButton1Button(self, event):
        TipoRecurso = self.textCtrl3.GetValue()
        
        #SE tipo de recurso for "servicos", pega os valores do contato do servico
        if TipoRecurso == 'servicos':
            rec = self.SalvarRecursoServico()
            
        elif TipoRecurso == 'bebidas':
            rec = self.SalvarRecursoBebida()
        
        elif TipoRecurso == 'comidas':
            rec = self.SalvarRecursoComida()
        
        else:
            Nome = self.textCtrl1.GetValue()
            Descricao = self.textCtrl2.GetValue()
            TipoRecurso = self.textCtrl3.GetValue()
            rec = Recurso(Nome, Descricao, TipoRecurso)
            
        if rec <> False:
            confirmacao = self.GR.CadastrarRecurso(rec)
            if confirmacao == True:
                m = 'Recurso Cadastrado com sucesso'
                t = 'Cadastro de Recurso - Servicos'
                wx.MessageBox(m,t, wx.OK)
                self.Close()
        else:
            m = 'Recurso nao foi cadastrado'
            t = 'Cadastro de Recurso'
            wx.MessageBox(m,t, wx.ICON_ERROR)
        
    def SalvarRecursoServico(self):
        
        Nome = self.textCtrl1.GetValue()
        Descricao = self.textCtrl2.GetValue()
        TipoRecurso = self.textCtrl3.GetValue()
        
        Email = self.textCtrl4.GetValue()
        Telefone1 = self.textCtrl5.GetValue()
        Telefone2 = self.textCtrl6.GetValue()
        Telefone3 = self.textCtrl7.GetValue()
        
        #Se os campos necessario (email e telefone) nao forem preenchidos, 
        #exibe uma msg de erro
        if Email == '' or Telefone1 == '':
            m = 'Favor Preencher todos os dados solicitados'
            t = 'Cadastro de Recurso - Servicos'
            wx.MessageBox(m,t, wx.ICON_ERROR)
            R = False
        else:
            Cont = Contato(Telefone1, Telefone2, Telefone3, Email)
            R = Recurso(Nome, Descricao, TipoRecurso, Cont)
            print R.GetContato().GetTelefone1()
        return R
    
    def SalvarRecursoComida(self):
        Salgada = self.radioButton1.GetValue()
        Nome = self.textCtrl1.GetValue()
        Descricao = self.textCtrl2.GetValue()
        TipoRecurso = self.textCtrl3.GetValue()
        
        RC = RecursoComida(Nome, Descricao, TipoRecurso)
        if Salgada == True:
            RC.SetTipoComida('1')
        else:
            RC.SetTipoComida('2')
            
        return RC
    
    def SalvarRecursoBebida(self):
        
        Nome = self.textCtrl1.GetValue()
        Descricao = self.textCtrl2.GetValue()
        TipoRecurso = self.textCtrl3.GetValue()
        RB = RecursoBebida(Nome, Descricao, TipoRecurso)
        
        Alcoolica = self.radioButton3.GetValue()
        if Alcoolica == True:
            RB.SetTipoBebida('1')
        else:
            RB.SetTipoBebida('2')
            
        return RB

    #Botao: "Cancelar"
    def OnButton2Button(self, event):
        self.Close()
